package com.rongji.dfish.hello.service;

import com.rongji.dfish.base.Pagination;
import com.rongji.dfish.base.util.Utils;
import com.rongji.dfish.framework.service.impl.AbstractFrameworkService;
import com.rongji.dfish.hello.constant.DemoConstants;
import com.rongji.dfish.hello.dao.OrgDao;
import com.rongji.dfish.hello.dao.UserDao;
import com.rongji.dfish.hello.entity.SysUser;
import com.rongji.dfish.hello.entity.SysUser;
import com.rongji.dfish.hello.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class UserService extends AbstractFrameworkService<UserModel, SysUser, String> {

    @Autowired
    private UserDao dao;

    @Override
    public UserDao getDao() {
        return dao;
    }

    public void setDao(UserDao dao) {
        this.dao = dao;
    }

    @Override
    public SysUser newInstance4Po() {
        return new SysUser();
    }

    @Override
    public UserModel newInstance4Vo() {
        return new UserModel();
    }

    public List<UserModel> list(Pagination pagination, Map<String, Object> params) {
        List<SysUser> userList = dao.list(pagination, params);
        List<UserModel> models = new ArrayList<>(userList.size());
        for (SysUser user : userList) {
            UserModel model = getInstance4Vo(user);
            model.setGenderName("1".equals(user.getGender()) ? "男" : "女");
            model.setUserStatusName("1".equals(user.getUserStatus()) ? "启用" : "禁用");
            models.add(model);
        }
        return models;
    }

    public int updateStatus(String orgId, String orgStatus) {
        return dao.updateStatus(orgId, orgStatus);
    }

}
